package com.tencent.mid.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Environment;
import android.os.StatFs;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import java.io.File;

public class h
{
  public static DisplayMetrics a(Context paramContext)
  {
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    ((WindowManager)paramContext.getApplicationContext().getSystemService("window")).getDefaultDisplay().getMetrics(localDisplayMetrics);
    return localDisplayMetrics;
  }

  public static String a()
  {
    try
    {
      long l1 = b() / 1000000L;
      Object localObject = new StatFs(Environment.getDataDirectory().getPath());
      long l2 = ((StatFs)localObject).getBlockSize();
      l2 = ((StatFs)localObject).getAvailableBlocks() * l2 / 1000000L;
      localObject = String.valueOf(l2) + "/" + String.valueOf(l1);
      return localObject;
    }
    catch (Throwable localThrowable)
    {
      Util.logWarn(localThrowable);
    }
    return ((String)"");
  }

  public static long b()
  {
    StatFs localStatFs = new StatFs(Environment.getDataDirectory().getPath());
    long l = localStatFs.getBlockSize();
    return (localStatFs.getBlockCount() * l);
  }

  public static String b(Context paramContext)
  {
    try
    {
      if (Util.checkPermission(paramContext, "android.permission.READ_PHONE_STATE"))
      {
        paramContext = (TelephonyManager)paramContext.getSystemService("phone");
        if (paramContext == null)
          break label45;
        paramContext = paramContext.getSimOperator();
        break label47:
      }
      Util.logInfo("Could not get permission of android.permission.READ_PHONE_STATE");
      return null;
    }
    catch (Throwable paramContext)
    {
      Util.logWarn(paramContext);
      return null;
    }
    label45: paramContext = null;
    label47: return paramContext;
  }

  public static String c(Context paramContext)
  {
    try
    {
      String str = paramContext.getPackageManager().getPackageInfo(paramContext.getPackageName(), 0).versionName;
      paramContext = str;
      if (str == null)
        paramContext = "";
      return paramContext;
    }
    catch (Throwable paramContext)
    {
      Util.logWarn(paramContext);
    }
    return "";
  }

  public static String d(Context paramContext)
  {
    Object localObject;
    try
    {
      if ((Util.checkPermission(paramContext, "android.permission.INTERNET")) && (Util.checkPermission(paramContext, "android.permission.ACCESS_NETWORK_STATE")))
      {
        localObject = ((ConnectivityManager)paramContext.getSystemService("connectivity")).getActiveNetworkInfo();
        if ((localObject == null) || (!(((NetworkInfo)localObject).isConnected())))
          break label106;
        paramContext = ((NetworkInfo)localObject).getTypeName();
        localObject = ((NetworkInfo)localObject).getExtraInfo();
        if (paramContext == null)
          break label106;
        if (paramContext.equalsIgnoreCase("WIFI"))
          return "WIFI";
        if (!(paramContext.equalsIgnoreCase("MOBILE")))
          break label100;
        if (localObject == null)
          break label97;
        return localObject;
      }
      Util.logInfo("can not get the permission of android.permission.ACCESS_WIFI_STATE");
      return null;
    }
    catch (Throwable paramContext)
    {
      Util.logWarn(paramContext);
      return null;
    }
    label97: return "MOBILE";
    if (localObject != null)
    {
      label100: return localObject;
      label106: paramContext = null;
    }
    return ((String)paramContext);
  }

  public static Integer e(Context paramContext)
  {
    try
    {
      paramContext = (TelephonyManager)paramContext.getSystemService("phone");
      if (paramContext == null)
        break label25;
      int i = paramContext.getNetworkType();
      return Integer.valueOf(i);
    }
    catch (Throwable paramContext)
    {
    }
    label25: return null;
  }

  public static String f(Context paramContext)
  {
    try
    {
      if (Util.checkPermission(paramContext, "android.permission.WRITE_EXTERNAL_STORAGE"))
      {
        paramContext = Environment.getExternalStorageState();
        if ((paramContext == null) || (!(paramContext.equals("mounted"))))
          break label122;
        paramContext = Environment.getExternalStorageDirectory().getPath();
        if (paramContext == null)
          break label122;
        paramContext = new StatFs(paramContext);
        long l1 = paramContext.getBlockCount() * paramContext.getBlockSize() / 1000000L;
        long l2 = paramContext.getAvailableBlocks();
        l2 = paramContext.getBlockSize() * l2 / 1000000L;
        return String.valueOf(l2) + "/" + String.valueOf(l1);
      }
      Util.logInfo("can not get the permission of android.permission.WRITE_EXTERNAL_STORAGE");
      return null;
    }
    catch (Throwable paramContext)
    {
      Util.logWarn(paramContext);
    }
    label122: return null;
  }
}